# coding: utf-8
import sys

from PySide6.QtCore import QStandardPaths
from qfluentwidgets import QConfig, ColorConfigItem, ConfigItem, FolderValidator, OptionsValidator, OptionsConfigItem, \
    BoolValidator, Theme, qconfig

from .setting import CONFIG_DIR, DEFAULT_DOWNLOAD_DIR


def isWin11():
    return sys.platform == 'win32' and sys.getwindowsversion().build >= 22000


class Config(QConfig):
    """ Config of application """
    themeColor = ColorConfigItem("QFluentWidgets", "ThemeColor", '#ae3ec9')
    # download
    downloadFolder = ConfigItem("Folder", "DownloadFolder", DEFAULT_DOWNLOAD_DIR.as_posix(), FolderValidator())

    # main window
    micaEnabled = ConfigItem("MainWindow", "MicaEnabled", isWin11(), BoolValidator())
    dpiScale = OptionsConfigItem(
        "MainWindow", "DpiScale", "Auto", OptionsValidator([1, 1.25, 1.5, 1.75, 2, "Auto"]), restart=True)


cfg = Config()
cfg.themeMode.value = Theme.AUTO
qconfig.load(CONFIG_DIR / 'config.json', cfg)
